package com.client.clovece;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.List;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Observer;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;

public class LocalMenu extends JFrame implements ActionListener{

	private JButton startb, endb, loadb, backb;
	private JLabel numpl;
	private JSpinner numps;
	private JTextField loadt;
	private String mystate = "";
	private MainMenu myParent;
	private LocalGame lg;
	private String savePath;
	
	public LocalMenu(MainMenu parent, Point p){
		Container c = getContentPane();
		JPanel ctrls = new JPanel();
	    SpinnerModel sm = new SpinnerNumberModel(2,2,4,1);
	    
	    myParent = parent;
	    
		startb = new JButton("Start hry");
		endb = new JButton("Konec hry");
		loadb = new JButton("Nacti ulozenou");
		backb = new JButton("Zpet");
		numpl = new JLabel("Pocet hracu", JLabel.CENTER);
		loadt = new JTextField("Cesta k nactene hre");
		numps = new JSpinner(sm);
		
		ctrls.setLayout( new BoxLayout(ctrls, BoxLayout.Y_AXIS));
		ctrls.add(numpl);
		ctrls.add(numps);
		ctrls.add(loadb);
		ctrls.add(loadt);
		ctrls.add(startb);
		ctrls.add(backb);
		ctrls.add(endb);
		
		setGui();
		c.add(ctrls);
		setLocation(p);
		setVisible(true);
	}
	
	public void setGui(){
		Dimension d = new Dimension(270,20);
		
		startb.setAlignmentX(Component.CENTER_ALIGNMENT);
		startb.setMaximumSize(d);
		startb.addActionListener(this);
		endb.setAlignmentX(Component.CENTER_ALIGNMENT);
		endb.setMaximumSize(d);
		endb.addActionListener(this);
		loadb.setAlignmentX(Component.CENTER_ALIGNMENT);
		loadb.setMaximumSize(d);
		backb.setAlignmentX(Component.CENTER_ALIGNMENT);
		backb.setMaximumSize(d);
		backb.addActionListener(this);
		numpl.setAlignmentX(Component.CENTER_ALIGNMENT);
		numpl.setMaximumSize(d);
		loadt.setAlignmentX(Component.CENTER_ALIGNMENT);
		loadt.setMaximumSize(d);
		numps.setAlignmentX(Component.CENTER_ALIGNMENT);	
		numps.setMaximumSize(d);
		
		setSize(640, 480);
	    setDefaultCloseOperation(EXIT_ON_CLOSE);
		setResizable(false);
	}
	
	public void actionPerformed(ActionEvent e) {
		Object o = e.getSource();
		if(o == backb){
			Point p = getLocation();
			myParent.update("setVisible", p);
			this.dispose();
		}
		else if(o == endb){
			System.exit(0);
		}
		else if(o == startb){
			System.out.println(System.getProperty("user.dir")+"\n");
			lg = new LocalGame(this, (Integer)numps.getValue(), savePath);
		}
	}

}
